package club.emergency.wechat.authorization.operate.consumer.service.fallback_factory;

import club.emergency.wechat.authorization.operate.consumer.service.AuthorizationOperateConsumer;
import club.emergency.wechat.common.response.ResponseEntity;
import club.emergency.wechat.common.response.StatusCode;
import club.emergency.wechat.model.role.Role;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * Create with IntelliJ IDEA
 * Project Name: wechat
 * Package Name: club.emergency.wechat.authorization.operate.consumer.service.fallback_factory
 * Date: 2019/3/25
 *
 * @author: 快乐的小菌菌
 * Description:
 */
@Component
public class AuthorizationOperateFallbackFactory implements FallbackFactory<AuthorizationOperateConsumer> {

    @Override
    public AuthorizationOperateConsumer create(Throwable throwable) {
        return new AuthorizationOperateConsumer() {
            @Override
            public String saveRole(Role role, String authorizationIds) {
                return ResponseEntity.error(StatusCode.DB_SAVE_ERROR, "角色新增错误！", throwable.getMessage());
            }

            @Override
            public String editRole(Role role, String authorizationIds) {
                return ResponseEntity.error(StatusCode.DB_MODIFY_ERROR, "角色修改错误！", throwable.getMessage());
            }

            @Override
            public String removeRole(Long id) {
                return ResponseEntity.error(StatusCode.DB_MODIFY_ERROR, "角色删除错误！", throwable.getMessage());
            }

            @Override
            public String bindManager(Long managerId, String roleIds) {
                return ResponseEntity.error(StatusCode.DB_MODIFY_ERROR, "角色绑定错误！", throwable.getMessage());
            }
        };
    }

}
